﻿//#define bRet
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Demo_MVVM基本框架.View.MyUserControl;

namespace Demo_MVVM基本框架.Model
{
    class ModelMainWindow : NotifyPropertyChange//逻辑
    {
        #region 建立单例

        private static ModelMainWindow uniqueInstance;

        private static readonly object locker = new object();

        public static ModelMainWindow GetInstance()
        {
            if (uniqueInstance == null)
            {
                lock (locker)
                {
                    if (uniqueInstance == null)
                    {
                        uniqueInstance = new ModelMainWindow();
                    }
                }
            }
            return uniqueInstance;
        }

        #endregion



        private string _TC = "333";
        public string TC
        {
            get { return _TC; }
            set { if (_TC != value) { _TC = value; RaisePropertyChanged(""); } }
        }
        private ObservableCollection<string> _LClientItem;
        public ObservableCollection<string> LClientItem
        {
            get { return _LClientItem; }
            set { if (_LClientItem != value) { _LClientItem = value; RaisePropertyChanged(""); } }
        }

        //1.定义回调函数指针.
        private delegate void MsgHandler(string strMsg);

        //2.定义回调函数.
        private event MsgHandler f;

        public void HMain2()
        {
#if bRet
            MainWindow e = new MainWindow();
            //3.连接函数指针对象f到t.OnMsg.

            f = new MsgHandler(e.MyView.OnMsg);

            //4.调用指针的回调函数
            f("Hello,Delegate!");

            e.Close();
#else
            //3.连接函数指针对象f到t.OnMsg.
            f = new MsgHandler(((MainWindow)System.Windows.Application.Current.MainWindow).MyView.OnMsg);

            //4.调用指针的回调函数
            f("Hello,Delegate!");
#endif

        }


    }




}
